package Orders;

import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

public class OrderBean extends OrderReducer implements WritableComparable<OrderBean> {
   private  int Order_id;
   private  double price;

    public OrderBean() {

    }

    public OrderBean(int order_id, double price) {
        Order_id = order_id;
        this.price = price;
    }

    public int getOrder_id() {
        return Order_id;
    }

    public void setOrder_id(int order_id) {
        Order_id = order_id;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }
    //序列化
    @Override
    public void write(DataOutput out) throws IOException {
        out.writeInt(Order_id);
        out.writeDouble(price);
    }
   //反序列化
    @Override
    public void readFields(DataInput in) throws IOException {
       this.Order_id = in.readInt();
       this.price = in.readDouble();
    }

    @Override
    public int compareTo(OrderBean o) {
        int result;
        if (this.Order_id > o.getOrder_id()) {
            return 1;
        } else if (this.Order_id < o.getOrder_id()) {
            return 1;

        }else {
            result =  this.price>o.price?1:-1;
        }
        return  result;
    }

    @Override
    public String toString() {
        return
                "Order_id=" + Order_id +"\t"+
                ", price=" + price ;
    }
}
